package com.gxg.demo10.mydemo11.titletest;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.gxg.demo10.mydemo11.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：Administrator on 2018/3/9 13:32
 * 邮箱：android_gaoxuge@163.com
 */
public class TitleTestActivity extends AppCompatActivity implements TranslucentScrollView.TranslucentChangedListener {
    @Bind(R.id.titlebar)
    TranslucentActionBar titlebar;
    @Bind(R.id.scv)
    TranslucentScrollView scv;
    private View zoomView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_title_test);
        ButterKnife.bind(this);

        titlebar.setBackgroud(R.color.orange_dft);
        titlebar.setData("TitleBar", R.drawable.ic_left_light, "", 0, "", new ActionBarClickListener() {
            @Override
            public void onLeftClick() {
                finish();
            }

            @Override
            public void onRightClick() {

            }
        });

        //开启渐变
        titlebar.setNeedTranslucent();
        //设置状态栏高度
        titlebar.setStatusBarHeight(getStatusBarHeight());

        //设置透明度变化监听
        scv.setTranslucentChangedListener(this);
        //关联需要渐变的视图
        scv.setTransView(titlebar);
        //设置ActionBar键渐变颜色
        scv.setTransColor(getResources().getColor(R.color.orange_dft));

        zoomView = findViewById(R.id.lay_header);
        //关联伸缩的视图
        scv.setPullZoomView(zoomView);

    }

    /**
     * 获取状态栏高度
     *
     * @return
     */
    public int getStatusBarHeight() {
        //获取status_bar_height资源的ID
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            return getResources().getDimensionPixelSize(resourceId);
        }
        return 0;
    }

    @Override
    public void onTranslucentChanged(int transAlpha) {
        titlebar.tvTitle.setVisibility(transAlpha > 48 ? View.VISIBLE : View.GONE);
    }
}
